home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter / MeshWriterTest / modules / wave.c < prev   
Encoding:
C/C++ Source or Header  |  1999-12-03  |  2.8 KB  |  94 lines

  1. /*
  2. **      $VER: wave.c 1.00 (20.3.1999)
  3. **
  4. **      Creation date     : 20.3.1999
  5. **
  6. **      Description       :
  7. **         MeshWriter testprogram shape module.
  8. **
  9. **
  10. **      Written by Stephan Bielmann
  11. **
  12. */
  13.  
  14. /*************************** Includes *******************************/
  15.  
  16. #ifndef WITHMWLLIB
  17. #include "//meshlib.h"
  18. #else
  19. #include <meshwriter/meshwriter.h>
  20. #include <pragma/meshwriter_lib.h>
  21. #endif
  22.  
  23. #include <math.h>
  24.  
  25. /**************************** Defines *******************************/
  26.  
  27. #define PI            3.14159265359
  28. #define WAVESTEPS     20
  29.  
  30. /*********************** Type definitions ***************************/
  31.  
  32. /********************** Private functions ***************************/
  33.  
  34. /********************** Public functions ****************************/
  35.  
  36. /********************************************************************\
  37. *                                                                    *
  38. * Name         : wave                                                *
  39. *                                                                    *
  40. * Description  : Draws a wave with the help of a formula got out of  *
  41. *                Plotter 3D by Sven Steiniger.                       *
  42. *                                                                    *
  43. * Arguments    : mesh    IN  : An initialized mesh handle.           *
  44. *                                                                    *
  45. * Comment      :                                                     *
  46. *                                                                    *
  47. \********************************************************************/
  48. void wave(ULONG mesh) {
  49.   ULONG m[3];
  50.   TOCLColor color;
  51.   TOCLVertex matrix[WAVESTEPS+1][WAVESTEPS+1];
  52.   ULONG x,y;
  53.   FLOAT u,v;
  54.  
  55.   MWLMeshMaterialAdd(mesh,&m[0]);
  56.   color.r=0,color.g=0,color.b=0;
  57.   MWLMeshMaterialDiffuseColorSet(mesh,m[0],&color);
  58.  
  59.   MWLMeshMaterialAdd(mesh,&m[1]);
  60.   color.r=255,color.g=0,color.b=0;
  61.   MWLMeshMaterialDiffuseColorSet(mesh,m[1],&color);
  62.  
  63.   MWLMeshMaterialAdd(mesh,&m[2]);
  64.   color.r=0,color.g=255,color.b=0;
  65.   MWLMeshMaterialDiffuseColorSet(mesh,m[2],&color);
  66.  
  67.   MWLMeshNameSet(mesh,"Wave");
  68.  
  69.   u=-PI;
  70.   for(x=0;x<WAVESTEPS+1;x++) {
  71.     v=-PI;
  72.       for(y=0;y<WAVESTEPS+1;y++) {
  73.         matrix[x][y].x=u;
  74.         matrix[x][y].y=v;
  75.         matrix[x][y].z=sin(u)+cos(v);
  76.  
  77.         v+=2*PI/WAVESTEPS;
  78.     }
  79.     u+=2*PI/WAVESTEPS;
  80.   }
  81.  
  82.   for(x=0;x<(WAVESTEPS);x++) {
  83.     for(y=0;y<(WAVESTEPS);y++) {
  84.       MWLMeshPolygonAdd(mesh,m[((ULONG)(matrix[x][y].z))+1]);
  85.       MWLMeshPolygonVertexAdd(mesh,&matrix[x][y]);
  86.       MWLMeshPolygonVertexAdd(mesh,&matrix[x+1][y]);
  87.       MWLMeshPolygonVertexAdd(mesh,&matrix[x+1][y+1]);
  88.       MWLMeshPolygonVertexAdd(mesh,&matrix[x][y+1]);
  89.     }
  90.   }
  91. }
  92.  
  93. /************************* End of file ******************************/
  94.